package pun.potato;

import java.util.Timer;
import java.util.TimerTask;

import android.os.CountDownTimer;
import android.widget.TextView;

public class MyTimer extends CountDownTimer {

	int minutes;
	int seconds;
	TextView text;
	PlayScreen screen;
	private boolean dead;
	
	public MyTimer(long millisInFuture, long countDownInterval) {
		super(millisInFuture, countDownInterval);
		int totalSeconds = (int)(millisInFuture / 1000);
		minutes = totalSeconds / 60;
		seconds = totalSeconds % 60;
		dead = false;
	}
	
	public boolean getDead(){
		return dead;
	}

	@Override
	public void onFinish() {

		dead = true;
		if(PlayScreen.yourTurn){
			text.setText("YOU LOST!!!");
		}
		else{
			text.setText("YOU WON!!!");
		}
		
        TimerTask task = new TimerTask(){
        	public void run(){
        		screen.endGame();     		
        	}
        };        
        Timer internalTimer = new Timer();
        internalTimer.schedule(task, 3000);
			
		
		
	}

	@Override
	public void onTick(long millisUntilFinished) {
		int totalSeconds = (int)(millisUntilFinished / 1000);
		minutes = totalSeconds / 60;
		seconds = totalSeconds % 60;
		if(seconds < 10){
			text.setText(minutes + ":0" + seconds);
		}
		else{
			text.setText(minutes + ":" + seconds);
		}
		
	}
	
	public void setTextView(TextView view, PlayScreen s){
		text = view;
		screen = s;
	}

	
	
}
